package com.be.beadmin.system.controller.ProductMaterialController;

import com.be.beadmin.common.utils.ResultModel;
import com.be.beadmin.system.service.ProductMaterialService.WorkOrderInforPmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * @Description:
 * @author: Jiaming Zheng
 * @Date: Create in 15:20 2023/6/20
 * @Modified By:
 **/
@Api(tags = {"生产-物料公共模块-工单管理"})
@RestController
public class WorkOrderInforPmController {

    @Autowired
    private WorkOrderInforPmService workOrderInforPdService;
    @ApiOperation("释放工单(工单管理界面的释放)") //   const status = ['未释放', '已释放', '执行中', '已完成'];
    @PostMapping("/product/releaseWorkOrderInfor")
    public ResultModel releaseWorkOrderInfor(@RequestParam String workOrderInfoId){
        int result = workOrderInforPdService.releaseWorkOrderInfor(workOrderInfoId);
        if (result == -1) return ResultModel.error(result,"工单已释放，请不要重复释放");
        if (result == -2) return ResultModel.error(result,"未找到该工单");
        if (result == -3) return ResultModel.success("计划没有调整过，工单已释放");
//        if (result == -4) return ResultModel.success("图纸没有打印过，工单已释放");
        return ResultModel.success("工单已释放");
    }

    @ApiOperation("获取该工单的BOM信息")
    @PostMapping(value = "/product/getBomOverview")
    public ResultModel getBomOverview(@ApiParam(value = "工单ID") @RequestParam String workOrderInfoId
//                                      @ApiParam(value = "是否分料0-未发（）1-已发") @RequestParam int isDivided
    )  {
        return ResultModel.success(workOrderInforPdService.getBomOverview(workOrderInfoId)) ;
    }

    @ApiOperation("下发工单(设计界面的下发)")
    @PostMapping(value = "/product/issueWorkOrderInforByPage")
    public ResultModel issueWorkOrderInforByPage(@RequestBody List<String> batchProductId) throws ParseException {
        return ResultModel.success(workOrderInforPdService.issueWorkOrderInforByPage(batchProductId)) ;
    }

    @ApiOperation("关闭工单")
    @PostMapping(value = "/product/closeWorkOrderInfor")
    public ResultModel closeWorkOrderInfor(@RequestParam String workOrderInfoId)  {
        workOrderInforPdService.closeWorkOrderInfor(workOrderInfoId);
        return ResultModel.success("工单关闭成功") ;
    }

}
